<?php
if (isset($_SESSION['admin-login'])) {
	if (isset($_SESSION['status-blog'])) {
		echo "<p>".$_SESSION['status-blog']."</p>";
		unset($_SESSION['status-blog']);
	}
	echo "<p><a href=\"".site()."/".$param[0]."/blog-new\">Buat artikel baru</a></p>";
	$blogs = db_array("SELECT * FROM blog ORDER BY tgl DESC");
	if ($blogs == false) {
		echo "Tidak ada artikel";
	} else {
		foreach ($blogs as $blog) {
			?>
			<br><br><?php echo $blog['judul'] ?><br>
			<?php echo $blog['tgl'] ?><br>
			<a href="<?php echo site()."/".$param[0]."/blog-edit/".$blog['id'] ?>">Edit</a> - 
			<a href="<?php echo site()."/".$param[0]."/blog-hapus/".$blog['id'] ?>" onclick="return confirmHapus()">Hapus</a>
			<?php
		}
		?>
		<script type="text/javascript">
			function confirmHapus() {
				return confirm("Anda yakin?");
			}
		</script>
		<?php
	}
} else {
	$_SESSION['status-login'] = "Log in terlebih dahulu untuk melanjutkan";
	header("Location: ".site()."/".$param[0]."/login");
}
?>